{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "737bce11",
   "metadata": {},
   "source": [
    "#### Copyright 2021 The Cirq Developers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6db8c987",
   "metadata": {},
   "outputs": [],
   "source": [
    "# @title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
    "# you may not use this file except in compliance with the License.\n",
    "# You may obtain a copy of the License at\n",
    "#\n",
    "# https://www.apache.org/licenses/LICENSE-2.0\n",
    "#\n",
    "# Unless required by applicable law or agreed to in writing, software\n",
    "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
    "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
    "# See the License for the specific language governing permissions and\n",
    "# limitations under the License."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "88f3b242",
   "metadata": {},
   "source": [
    "### Cirq-web 3D circuit visualization"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9f4089af",
   "metadata": {},
   "source": [
    "\n",
    "<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
    "  <td>\n",
    "    <a target=\"_blank\" href=\"https://colab.research.google.com/github/quantumlib/Cirq/blob/main/cirq-web/circuit_example.ipynb\"><img src=\"https://quantumai.google/site-assets/images/buttons/colab_logo_1x.png\" />Run in Google Colab</a>\n",
    "  </td>\n",
    "  <td>\n",
    "    <a target=\"_blank\" href=\"https://github.com/quantumlib/Cirq/blob/main/cirq-web/circuit_example.ipynb\"><img src=\"https://quantumai.google/site-assets/images/buttons/github_logo_1x.png\" />View source on GitHub</a>\n",
    "  </td>\n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99172e40",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install --quiet cirq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fe0d0e69",
   "metadata": {},
   "outputs": [],
   "source": [
    "import cirq\n",
    "\n",
    "qubits = [cirq.GridQubit(x, y) for x in range(10) for y in range(10)]\n",
    "\n",
    "import cirq.testing\n",
    "\n",
    "circuit = cirq.testing.random_circuit(cirq.GridQubit.square(10), n_moments=5, op_density=0.7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "81689b3f",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "This cell builds a 3D circuit diagram using a big list of operations provided TS Circuit class.\n",
    "\"\"\"\n",
    "\n",
    "import cirq_web\n",
    "from cirq_web.circuits.symbols import SymbolInfo\n",
    "\n",
    "\n",
    "class FunkyHadamard(cirq_web.circuits.symbols.SymbolResolver):\n",
    "    def resolve(self, operation: cirq.Operation) -> SymbolInfo | None:\n",
    "        if isinstance(operation.gate, cirq.HPowGate):\n",
    "            return SymbolInfo(['Hello!'], ['yellow'])\n",
    "        else:\n",
    "            return None\n",
    "\n",
    "\n",
    "resolvers = list(cirq_web.circuits.symbols.DEFAULT_SYMBOL_RESOLVERS) + [FunkyHadamard()]\n",
    "\n",
    "from cirq_web import Circuit3D\n",
    "\n",
    "c3d = Circuit3D(circuit, resolvers, 2.5)\n",
    "display(c3d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "139acc3d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
